package com.eliza.base

import android.app.PendingIntent
import android.bluetooth.BluetoothDevice
import android.content.Intent
import android.content.IntentFilter
import android.nfc.NfcAdapter
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.eliza.base.ui.theme.HomeApplicationTheme
import com.eliza.base.views.NavHostMain
import com.eliza.library.device.bluethooth.BluetoothTool
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class RoutingActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Register for broadcasts when a device is discovered.
        registerReceiver(BluetoothTool.receiver, IntentFilter(BluetoothDevice.ACTION_FOUND))
        setContent {
            HomeApplicationTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    NavHostMain()
                }
            }
        }
    }

    override fun onResume() {
        super.onResume()
        val intent = Intent(this, javaClass).apply {
            addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING)
            action = NfcAdapter.ACTION_NDEF_DISCOVERED
            data = intent.data
        }
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
//        nfcAdapter?.enableForegroundDispatch(this, pendingIntent, null, null)

    }

    override fun onDestroy() {
        super.onDestroy()
        unregisterReceiver(BluetoothTool.receiver)
    }

}

